The section describes the programming interface of the SPI slave mode Peripheral driver.
More...
Overview
The SPI slave peripheral driver provides an easy way to use an SPI peripheral in slave mode.Data transfer is performed through callback functions.
Callbacks
To use this driver, first define several application callbacks. These are the callback functions that are set in the
spi_slave_callbacks_t structure.The three callbacks are:
- Data source
- Data sink
- Error notification
The first two callbacks are used to send and receive data. The third callback is invoked if an error occurs.The prototypes for the three callbacks are:
status_t dataSource(uint8_t * sourceByte, uint16_t instance);
status_t dataSink(uint8_t sinkByte, uint16_t instance);
void onError(status_t error);
All callbacks are invoked from IRQ state.
Setup
To initialize the SPI slave driver, first create and fill in the #spi_slave_config_t structure. This structure defines the callbacks and data format settings for the SPI peripheral. The structure is not required after the driver is initialized and can be allocated on the stack.This is an example of a config struct definition:
spi_slave_config_t config = {
{
appDataSource,
appDataSink,
appErrorHandler,
},
};